package com.spark.sniffer.plugin.plugins.define.trace;

import static net.bytebuddy.matcher.ElementMatchers.named;
import com.spark.sniffer.plugin.interceptor.InstanceMethodsInterceptPoint;
import com.spark.sniffer.plugin.interceptor.StaticMethodsInterceptPoint;
import com.spark.sniffer.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import com.spark.sniffer.plugin.match.ClassMatch;
import com.spark.sniffer.plugin.match.NameMatch;
import com.spark.sniffer.plugin.plugins.interceptor.AsyncHttpClientInterceptor;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;

public class AsyncHttpClientPlugin extends ClassInstanceMethodsEnhancePluginDefine {

  @Override
  protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
    return new InstanceMethodsInterceptPoint[] {new InstanceMethodsInterceptPoint() {
      @Override
      public ElementMatcher<MethodDescription> getMethodsMatcher() {
        return named("execute");
      }

      @Override
      public Class<?> getMethodsInterceptor() {
        return AsyncHttpClientInterceptor.class;
      }

      @Override
      public boolean isOverrideArgs() {
        return false;
      }
    }};
  }

  @Override
  protected StaticMethodsInterceptPoint[] getStaticMethodsInterceptPoints() {
    return new StaticMethodsInterceptPoint[0];
  }

  @Override
  protected ClassMatch enhanceClass() {
    return NameMatch.byName("org.asynchttpclient.BoundRequestBuilder");
  }

}
